package com.xcc.httpUtils.builder;

import com.xcc.httpUtils.request.PostRequest;
import com.xcc.httpUtils.request.RequestCall;

import java.util.LinkedHashMap;
import java.util.Map;


/**
 * Created by Carman on 2017/7/7.
 * <p>
 * post 请求参数设置
 */
public class PostBuilder extends BaseHttpRequestBuilder<PostBuilder> {

    public PostBuilder(String url) {
        super(url);
    }

    /**
     * 添加 参数
     *
     * @param key   参数名
     * @param value 参数值
     * @return PostRequestBuilder 当前对象
     */
    public PostBuilder addParams(String key, String value) {
        if (this.params == null) {
            params = new LinkedHashMap<>();
        }
        params.put(key, value);
        return this;
    }

    /**
     * 添加参数
     *
     * @param params 参数
     * @return PostRequestBuilder 当前对象
     */
    public PostBuilder params(Map<String, String> params) {
        if (this.params != null) {
            params.clear(); //如果已有添加参数,清空参数
        }
        this.params = params;
        return this;
    }

    @Override
    public RequestCall build() {
        return new PostRequest(url, tag, params, headers, json).build();
    }
}
